package com.ymatou.iapi.trading.operate.testcase;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.BargainGroupService;
import com.ymatou.iapi.trading.operate.parameter.OrderItemVo;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymatou.iapi.trading.operate.parameter.enums.LogisticsTypeEnum;
import com.ymatou.iapi.trading.operate.parameter.req.AcceptOrderBean;
import com.ymatou.iapi.trading.operate.parameter.req.PlaceOrderReq;
import com.ymatou.iapi.trading.operate.service.AcceptOrderCall;
import com.ymt.base.YmatouEasyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.constant.ECode;

public class Ts_AcceptOrder {
	private static AcceptOrderBean acceptorderbean;
	private static AcceptOrderCall acceptordercall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("卖家接单");
	}

	@Before
	public void caseUp() {
		acceptorderbean = new AcceptOrderBean();
		acceptordercall = new AcceptOrderCall();

	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(acceptordercall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	 * 
	 * 优选买手订单
	 */
	public static PlaceOrderResp placeOrder2() {

		PlaceOrderReq placeorderBean = PlaceOrderService.getDefaultOrderReq();

		//不使用平台券
		placeorderBean.setYmatouCoupon(null);
		//不使用商家券
		placeorderBean.getOrderGroups().get(0).setSellerCoupon(null);

		placeorderBean.getOrderGroups().get(0).setOptimumSeller(true);

		return PlaceOrderService.callPlaceOrderService(placeorderBean);

	}

	/**
	 * 
	 * 贝海直邮订单，订单价格超过2000
	 */
	public static PlaceOrderResp placeOrder(String name,
			LogisticsTypeEnum logisticsType) {

		PlaceOrderReq placeorderBean = PlaceOrderService.getDefaultOrderReq();

		//不使用平台券
		placeorderBean.setYmatouCoupon(null);
		//不使用商家券
		placeorderBean.getOrderGroups().get(0).setSellerCoupon(null);

		OrderItemVo orderItemVo = placeorderBean.getOrderGroups().get(0)
				.getOrders().get(0).getOrderItems().get(0);

		placeorderBean.getOrderGroups().get(0).getOrders().get(0)
				.setReceiveName(name);

		orderItemVo.setLogisticsType(logisticsType);

		orderItemVo.setProductPrice(new BigDecimal(2001));
		orderItemVo.setEarnestPrice(new BigDecimal(2001));
		orderItemVo.setOriginalPrice(new BigDecimal(2001));

		orderItemVo.setProductNum(1);

		return PlaceOrderService.callPlaceOrderService(placeorderBean);

	}
	// 数据库检查点
	private void verifyDb() {
		DefaultWapper database = new DefaultWapper();
		HashMap m = new HashMap();
		m.put("OrderId", acceptorderbean.getOrderId());
		m.put("TradingStatus", 17);
		m.put("TraddingId", acceptorderbean.getOrderId());
		m.put("UserId", acceptorderbean.getSellerId());
		Logger.verifyEquals(17,
				(Integer) database.selectOrder(m).get(0).get("iTradingStatus"),
				"验证订单表状态");
		Logger.verifyEquals(17,
				database.selectTradingStatus(m).get(0).get("iTradingStatus"),
				"验证交易表状态");
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AcceptOrder_001() {
		Logger.start(true, "卖家接单成功");
		try {
			// 创建订单
			Logger.comment("准备前置数据");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId((Integer) orderId);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, acceptordercall.getCode(),
					"验证Code");
			// 数据库验证
			verifyDb();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_AcceptOrder_002() {
		Logger.start(false, "订单不存在，卖家接单失败");
		try {
			Integer OrderId = 1048827;
			int SellerId = 288484;
			// 接单
			acceptorderbean.setOrderId(OrderId);// 订单ID
			Logger.comment("SellerId:" + SellerId);
			acceptorderbean.setSellerId(SellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, acceptordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("订单号" + OrderId + "不存在",
					acceptordercall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_AcceptOrder_003() {
		Logger.start(false, "订单为非支付成功状态，卖家接单失败");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId(orderId);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, acceptordercall.getCode(),
					"验证Code");
			Logger.verifyEquals(true,
					acceptordercall.getMsg().contains("订单状态不能确认接单"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_AcceptOrder_004() {
		Logger.start(false, "卖家重复接单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId(orderId);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, acceptordercall.getCode(),
					"验证Code");
			// 数据库验证
			verifyDb();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_AcceptOrder_005() {
		Logger.start(false, "卖家用户id不是订单的卖家");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId(orderId);// 订单ID
			acceptorderbean.setSellerId(sellerId + 1);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, acceptordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("用户" + acceptorderbean.getSellerId() + "不是订单"
					+ acceptorderbean.getOrderId() + "的所有者",
					acceptordercall.getMsg(), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_AcceptOrder_006() {
		Logger.start(false, "卖家用户id为null");
		try {
			// 接单
			acceptorderbean.setOrderId(1111);// 订单ID
			// acceptorderbean.setSellerId(sellerId+1);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, acceptordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("订单号" + acceptorderbean.getOrderId() + "不存在",
					acceptordercall.getMsg(), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_AcceptOrder_007() {
		Logger.start(false, "订单id为null");
		try {
			// 接单
			// acceptorderbean.setOrderId(orderId);// 订单ID
			acceptorderbean.setSellerId(1113);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.comment("卖家重复接单");
			acceptordercall.callService();
			Logger.verifyEquals(ECode.ERROR400, acceptordercall.getCode(),
					"验证Code");
			Logger.verifyIsContains("订单号不能为空", acceptordercall.getMsg(),
					"验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AcceptOrder_008() {
		Logger.start(false, "订单为风控不通过状态");
		try {
			// 创建订单
			Logger.comment("准备前置数据");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 模拟卖家 通知风控接口
			/*
			 * URL: http://api.trading.operate.ymatou.com/api/Notify/RiskControlNotify
			 * 
			 * /// 未检测，初始状态 Init = 1, /// 检测通过，不进行风控处理 Pass = 2, /// 检测未通过，需要立即进行风控处理(取消订单) Rejected
			 * = 3, /// 风控检测失败,滞留，需后续处理(滞留) Auditing = 4
			 * 风控检测未检测：{OrderId:105414523,ParamExt:{"Status":"Init"}}
			 * 风控检测未通过：{OrderId:105414523,ParamExt:{"Status":"Pass"}}
			 * 风控检测通过：{OrderId:105414517,ParamExt:{"Status":"Rejected"}}
			 * 风控检测失败：{OrderId:111111,ParamExt:{"Status":"Auditing"}}
			 */
			YmatouEasyCall RiskControlNotifyCall = new YmatouEasyCall("",
					"POST", "JSON");
			String RiskControlNotifyString = "{OrderId:" + orderId
					+ ",ParamExt:{\"Status\":\"Rejected\"}}";
			RiskControlNotifyCall
					.setUrl("http://api.trading.operate.ymatou.com/api/Notify/RiskControlNotify");
			RiskControlNotifyCall.setData(RiskControlNotifyString);
			Logger.comment("风控检测");
			RiskControlNotifyCall.callService();
			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId(orderId);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();

			Logger.verifyEquals(ECode.FAILED201, acceptordercall.getCode(),
					"验证Code");
			Logger.verifyEquals(true,
					acceptordercall.getMsg().contains("当前订单状态不能确认接单"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AcceptOrder_009() {
		Logger.start(false, "订单风控通过状态");
		try {
			// 创建订单
			Logger.comment("准备前置数据");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 模拟卖家 通知风控接口
			/*
			 * URL: http://api.trading.operate.ymatou.com/api/Notify/RiskControlNotify
			 * 
			 * /// 未检测，初始状态 Init = 1, /// 检测通过，不进行风控处理 Pass = 2, /// 检测未通过，需要立即进行风控处理(取消订单) Rejected
			 * = 3, /// 风控检测失败,滞留，需后续处理(滞留) Auditing = 4
			 * 风控检测未检测：{OrderId:105414523,ParamExt:{"Status":"Init"}}
			 * 风控检测未通过：{OrderId:105414523,ParamExt:{"Status":"Pass"}}
			 * 风控检测通过：{OrderId:105414517,ParamExt:{"Status":"Rejected"}}
			 * 风控检测失败：{OrderId:111111,ParamExt:{"Status":"Auditing"}}
			 */
			YmatouEasyCall RiskControlNotifyCall = new YmatouEasyCall("",
					"POST", "JSON");
			String RiskControlNotifyString = "{OrderId:" + orderId
					+ ",ParamExt:{\"Status\":\"Pass\"}}";
			RiskControlNotifyCall
					.setUrl("http://api.trading.operate.ymatou.com/api/Notify/RiskControlNotify");
			RiskControlNotifyCall.setData(RiskControlNotifyString);
			Logger.comment("风控检测");
			RiskControlNotifyCall.callService();
			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId(orderId);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID

			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, acceptordercall.getCode(),
					"验证Code");
			// 数据库验证

			verifyDb();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_AcceptOrder_010() {
		Logger.start(false, "订单风控检测失败状态");
		try {
			// 创建订单
			Logger.comment("准备前置数据");
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			// 模拟卖家 通知风控接口
			/*
			 * URL: http://api.trading.operate.ymatou.com/api/Notify/RiskControlNotify
			 * 
			 * /// 未检测，初始状态 Init = 1, /// 检测通过，不进行风控处理 Pass = 2, /// 检测未通过，需要立即进行风控处理(取消订单) Rejected
			 * = 3, /// 风控检测失败,滞留，需后续处理(滞留) Auditing = 4
			 * 风控检测未检测：{OrderId:105414523,ParamExt:{"Status":"Init"}}
			 * 风控检测未通过：{OrderId:105414523,ParamExt:{"Status":"Pass"}}
			 * 风控检测通过：{OrderId:105414517,ParamExt:{"Status":"Rejected"}}
			 * 风控检测失败：{OrderId:111111,ParamExt:{"Status":"Auditing"}}
			 */
			YmatouEasyCall RiskControlNotifyCall = new YmatouEasyCall("",
					"POST", "JSON");
			String RiskControlNotifyString = "{OrderId:" + orderId
					+ ",ParamExt:{\"Status\":\"Auditing\"}}";
			RiskControlNotifyCall
					.setUrl("http://api.trading.operate.ymatou.com/api/Notify/RiskControlNotify");
			RiskControlNotifyCall.setData(RiskControlNotifyString);
			Logger.comment("风控检测");
			RiskControlNotifyCall.callService();
			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId(orderId);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, acceptordercall.getCode(),
					"验证Code");
			Logger.verifyEquals(ECode.ErrStatusNotMatch,
					acceptordercall.getBCode(), "验证Code");
			Logger.verifyEquals(true,
					acceptordercall.getMsg().contains("前订单状态不能确认接单-风控审核中"),
					"验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AcceptOrder_011() {
		Logger.start(true, "砍价团订单支付成功后,砍价团服务通知交易组团成功,商家接单成功.");
		try {
			// 创建订单
			Logger.comment("准备前置数据");

			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);
			//砍价团id
			String bizId = placeOrderResp.getBizId();
			int userId = placeOrderResp.getUserId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			Integer orderId1 = placeOrderResp.getOrderList().get(0)
					.getOrderId();

			//砍价团参团订单
			PlaceOrderResp placeOrderResp2 = BargainGroupService
					.joinGroup(bizId);

			Integer orderId2 = placeOrderResp2.getOrderList().get(0)
					.getOrderId();

			BargainGroupService.notifyOrderBizStatus(bizId, orderId1, 1, 3);

			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId(orderId1);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, acceptordercall.getCode(),
					"验证Code");
			// 数据库验证
			verifyDb();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_AcceptOrder_012() {
		Logger.start(false, "砍价团订单支付成功后,砍价团服务通知交易成团消息之前,商家不允许接单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);
			//砍价团id
			String bizId = placeOrderResp.getBizId();
			int userId = placeOrderResp.getUserId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			Integer orderId1 = placeOrderResp.getOrderList().get(0)
					.getOrderId();

			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId(orderId1);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, acceptordercall.getCode(),
					"验证code");
			Logger.verifyEquals(ECode.ErrStatusNotMatch,
					acceptordercall.getBCode(), "验证bcode");
			Logger.verifyEquals("砍价团业务在成团前不能确认接单", acceptordercall.getMsg(),
					"验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_AcceptOrder_013() {
		Logger.start(false, "砍价团订单支付成功后,砍价团服务通知交易开团成功,商家不允许接单.");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);
			//砍价团id
			String bizId = placeOrderResp.getBizId();
			int userId = placeOrderResp.getUserId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			Integer orderId1 = placeOrderResp.getOrderList().get(0)
					.getOrderId();

			BargainGroupService.notifyOrderBizStatus(bizId, orderId1, 1, 1);

			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId(orderId1);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, acceptordercall.getCode(),
					"验证code");
			Logger.verifyEquals(ECode.ErrStatusNotMatch,
					acceptordercall.getBCode(), "验证bcode");
			Logger.verifyEquals("砍价团业务在成团前不能确认接单", acceptordercall.getMsg(),
					"验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_AcceptOrder_014() {
		Logger.start(false, "砍价团订单支付成功后,砍价团服务通知交易参团成功,商家不允许接单");
		try {
			// 创建订单
			Logger.comment("前置数据准备");
			PlaceOrderResp placeOrderResp = BargainGroupService.openGroup(null);
			//砍价团id
			String bizId = placeOrderResp.getBizId();
			int userId = placeOrderResp.getUserId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			Integer orderId1 = placeOrderResp.getOrderList().get(0)
					.getOrderId();

			//参团
			PlaceOrderResp placeOrderResp2 = BargainGroupService
					.joinGroup(bizId);

			Integer orderId2 = placeOrderResp2.getOrderList().get(0)
					.getOrderId();

			BargainGroupService.notifyOrderBizStatus(bizId, orderId2, 2, 2);

			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId(orderId1);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, acceptordercall.getCode(),
					"验证code");
			Logger.verifyEquals(ECode.ErrStatusNotMatch,
					acceptordercall.getBCode(), "验证bcode");
			Logger.verifyEquals("砍价团业务在成团前不能确认接单", acceptordercall.getMsg(),
					"验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AcceptOrder_015() {
		Logger.start(true,
				"贝海直邮商品订单电商件,订单收件人,订单金额不超过2000，但年消费额度超过20000,订单卖家接单失败.");
		try {
			// 创建订单
			Logger.comment("准备前置数据");

			String name = "李四";
			PlaceOrderResp placeOrderResp = Ts_OrderPayRequest.placeOrder2(
					name, LogisticsTypeEnum.SailProtect, true);

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);

			DefaultWapper database = new DefaultWapper();

			BigDecimal amount = new BigDecimal(20000);

			List<Map> list = database.executeSql(String.format(
					"select * from Ymt_OrderIdCardCostInfo where name='%s'",
					name));

			if (!CollectionUtils.isEmpty(list)) {
				database.executeUpdateSql(String
						.format("update Ymt_OrderIdCardCostInfo set amount='%s' where name='%s'",
								amount, name));
			}

			else {
				database.executeSql(String
						.format("insert into Ymt_OrderIdCardCostInfo values('370829198706012932','2017','%s',%s,getdate(),getdate())",
								name, amount));

			}

			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId((Integer) orderId);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.FAILED201, acceptordercall.getCode(),
					"验证Code");
			Logger.verifyEquals("102", acceptordercall.getBCode(), "验证bcode");

			Logger.verifyEquals("该收件人已经超过20000限额,请联系买家修改收件人信息后重新接单.",
					acceptordercall.getMsg(), "验证bcode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AcceptOrder_016() {
		Logger.start(true,
				"贝海直邮商品个人件,订单收件人,订单金额不超过2000，但年消费额度超过20000,订单卖家接单失败.");
		try {
			// 创建订单
			Logger.comment("准备前置数据");

			String name = "李四";
			PlaceOrderResp placeOrderResp = Ts_OrderPayRequest.placeOrder2(
					name, LogisticsTypeEnum.SailProtect, false);

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);

			DefaultWapper database = new DefaultWapper();

			BigDecimal amount = new BigDecimal(20000);

			List<Map> list = database.executeSql(String.format(
					"select * from Ymt_OrderIdCardCostInfo where name='%s'",
					name));

			if (!CollectionUtils.isEmpty(list)) {
				database.executeUpdateSql(String
						.format("update Ymt_OrderIdCardCostInfo set amount='%s' where name='%s'",
								amount, name));
			}

			else {
				database.executeSql(String
						.format("insert into Ymt_OrderIdCardCostInfo values('370829198706012932','2017','%s',%s,getdate(),getdate())",
								name, amount));

			}

			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId((Integer) orderId);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, acceptordercall.getCode(),
					"验证Code");
			// 数据库验证
			verifyDb();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AcceptOrder_017() {
		Logger.start(true, "贝海直邮商品订单,订单收件人,订单金额超过2000，年消费额度超过20000,卖家正常接单.");
		try {
			// 创建订单
			Logger.comment("准备前置数据");
			String name = "李四";
			PlaceOrderResp placeOrderResp = placeOrder(name,
					LogisticsTypeEnum.SailProtect);

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);

			BigDecimal amount = new BigDecimal(20000);

			DefaultWapper database = new DefaultWapper();

			List<Map> list = database.executeSql(String.format(
					"select * from Ymt_OrderIdCardCostInfo where name='%s'",
					name));

			if (!CollectionUtils.isEmpty(list)) {
				database.executeUpdateSql(String
						.format("update Ymt_OrderIdCardCostInfo set amount='%s' where name='%s'",
								amount, name));
			}

			else {
				database.executeSql(String
						.format("insert into Ymt_OrderIdCardCostInfo values('370829198706012932','2017','%s',%s,getdate(),getdate())",
								name, amount));

			}

			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId((Integer) orderId);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, acceptordercall.getCode(),
					"验证Code");
			// 数据库验证
			verifyDb();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AcceptOrder_018() {
		Logger.start(true, "非贝海直邮商品订单,订单收件人,订单金额不超过2000，年消费额度超过20000,卖家正常接单.");
		try {
			// 创建订单
			Logger.comment("准备前置数据");

			String name = "李四";
			PlaceOrderResp placeOrderResp = Ts_OrderPayRequest.placeOrder2(
					name, LogisticsTypeEnum.BondedDelivery, false);

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);

			BigDecimal amount = new BigDecimal(20000);

			DefaultWapper database = new DefaultWapper();

			List<Map> list = database.executeSql(String.format(
					"select * from Ymt_OrderIdCardCostInfo where name='%s'",
					name));

			if (!CollectionUtils.isEmpty(list)) {
				database.executeUpdateSql(String
						.format("update Ymt_OrderIdCardCostInfo set amount='%s' where name='%s'",
								amount, name));
			}

			else {
				database.executeSql(String
						.format("insert into Ymt_OrderIdCardCostInfo values('370829198706012932','2017','%s',%s,getdate(),getdate())",
								name, amount));

			}

			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId((Integer) orderId);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, acceptordercall.getCode(),
					"验证Code");
			// 数据库验证
			verifyDb();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AcceptOrder_019() {
		Logger.start(true, "非贝海直邮商品订单,订单收件人,订单金额超过2000，年消费额度超过20000,卖家正常接单.");
		try {
			// 创建订单
			Logger.comment("准备前置数据");
			String name = "李四";
			PlaceOrderResp placeOrderResp = placeOrder(name,
					LogisticsTypeEnum.SailProtect);

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();
			// 保留两位小数
			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);

			BigDecimal amount = new BigDecimal(20000);

			new DefaultWapper()
					.executeUpdateSql(String
							.format("update Ymt_OrderIdCardCostInfo set amount='%s' where id=3",
									amount));

			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId((Integer) orderId);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, acceptordercall.getCode(),
					"验证Code");
			// 数据库验证
			verifyDb();
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AcceptOrder_020() {
		Logger.start(true, "虚拟商品订单支付成功后,商家接单成功.");
		try {
			// 创建订单
			Logger.comment("准备前置数据");

			PlaceOrderResp placeOrderResp = BargainGroupService
					.placeVirtualProduct();

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId(orderId);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, acceptordercall.getCode(),
					"验证Code");
			// 数据库验证
			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AcceptOrder_021() {
		Logger.start(true, "微店拼邮订单支付成功后,商家自动接单成功.");
		try {
			// 创建订单
			Logger.comment("准备前置数据");

			PlaceOrderResp placeOrderResp = BargainGroupService
					.placeLiveWechar(LogisticsTypeEnum.PackageDelivery);

			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);
			Logger.comment("前置数据准备结束");

			Thread.sleep(2000);

			// 数据库验证
			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AcceptOrder_022() {
		Logger.start(true, "微店贝海直邮订单支付成功后,商家手动接单成功.");
		try {
			// 创建订单
			Logger.comment("准备前置数据");

			PlaceOrderResp placeOrderResp = BargainGroupService
					.placeLiveWechar(LogisticsTypeEnum.SailProtect);

			Integer orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);

			Thread.sleep(2000);

			Logger.comment("前置数据准备结束");
			// 接单
			acceptorderbean.setOrderId(orderId);// 订单ID
			acceptorderbean.setSellerId(sellerId);// 卖家ID
			// 发送请求
			acceptordercall.setData(acceptorderbean);
			acceptordercall.callService();
			Logger.verifyEquals(ECode.SUCCESS, acceptordercall.getCode(),
					"验证Code");

			// 数据库验证
			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AcceptOrder_023() {
		Logger.start(true, "优选买手订单支付成功后,商家手动接单成功.");
		try {
			// 创建订单
			Logger.comment("准备前置数据");

			PlaceOrderResp placeOrderResp = placeOrder2();

			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			// 支付订单
			new OrderCallService().orderPayRequest(userId, totalPrice,
					tradingId);

			Thread.sleep(2000);

			Logger.comment("前置数据准备结束");

			// 数据库验证
			verifyDb();

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
